#include "Logout.h"
#include "mini-printf.h"

UART_HandleTypeDef *loguart = &huart2;
static const char *TAG = "mavlink";

void uart_dma_printf(UART_HandleTypeDef *huart, char *fmt, ...)
{
    static uint8_t tx_buf[128] = {0};
    static va_list ap;
    static uint16_t len = 0;

    va_start(ap, fmt);
    len = mini_vsnprintf((char *)tx_buf, 128, fmt, ap);
    va_end(ap);

    tx_buf[len] = '\0';
    //   CDC_Transmit_FS(tx_buf, len);
    HAL_UART_Transmit_DMA(huart, tx_buf, len);
}

// todo分级
void LOGI(const char *tag, char *fmt, ...)
{
    static uint8_t buffer[128] = {0};
    static va_list args;

    va_start(args, fmt);
    mini_vsnprintf((char *)buffer, 128, fmt, args);
    va_end(args);

    static uint8_t tx_buf[128] = {0};
    static uint16_t len = 0;

    uint32_t timestamp = HAL_GetTick();
    len = mini_snprintf((char *)tx_buf, 128, "I (%d) %s: %s\n", timestamp, tag, buffer);

    //   CDC_Transmit_FS(tx_buf, len);
    HAL_UART_Transmit_DMA(loguart, tx_buf, len);
}
